<?

# Import the application settings.
require_once(dirname(__FILE__) . '/../config.php');

# Import the cart class.
require_once(APPLICATION_ROOT . '/cart/cartclass.php');

# Start a new session.
session_start();

# Point $cart to the session cart.
$cart =& $_SESSION['cart'];

# Transaction completed, clear the cart.
if ($cart) {
	$cart->clear_cart();
}

# If we received PDT, look up the details.
$txn_id = "";
if ($_GET['tx'] OR $_GET['txn_id'] OR $_GET['referenceId']) {

	if ($_GET['tx']) {
		$txn_id = filter_input(INPUT_GET, 'tx', FILTER_SANITIZE_STRING);
	} elseif ($_GET['referenceId']) {
		$txn_id = filter_input(INPUT_GET, 'referenceId', FILTER_SANITIZE_STRING);
	} else {
		$txn_id = filter_input(INPUT_GET, 'txn_id', FILTER_SANITIZE_STRING);
	}

}

# Construct the final URL from the transaction ID.
if ($txn_id) {
	$finalURL = filter_var(WEB_ROOT. "?txn_id=$txn_id", FILTER_SANITIZE_URL);
} else {
	$finalURL = WEB_ROOT;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>Purchase complete</title>
	</head>
	<body>
		<p><?php echo BSDDS_COMPLETED_MESSAGE; ?></p>
		<p><a href="<?php echo $finalURL; ?>">Download your purchases.</a></p>
	</body>
</html>